package com.carpedil.movie.config;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

/** @author Administrator */
@Component
public class MovieConfig implements WebMvcConfigurer {
  /**
   * 跨域配置,开启允许跨域
   *
   * @param registry registry
   */
  @Override
  public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").allowedHeaders("*");
  }

  /**
   * 静态资源以及虚拟路径配置
   *
   * @param registry registry
   */
  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    // 配置文件上传虚拟路径
    registry.addResourceHandler("/upload/**").addResourceLocations("file:f:/upload/");
  }

  /**
   * websocket需要的bean
   *
   * @return ServerEndpointExporter
   */
  @Bean
  public ServerEndpointExporter serverEndpointExporter() {
    return new ServerEndpointExporter();
  }
}
